package string;

import java.util.Arrays;

public class Test2 {
    public static void main(String[] args) {
        //通过构造器来构造String类型的对象
        //空构造器
        String s1 = new String();
        //字符串参数的构造器
        String s2 = new String("abc");
        //字符数组参数的构造器
        //在底层会通过传入的参数，形成一个新的数组，将数组通过copyOf传给value
        String s3 = new String(new char[]{'a','b','c'});


        String s4 = "abc";
        String s5 = new String();
        //length isEmpty charAt
        System.out.println("字符串的长度为"+s4.length());
        System.out.println("数组是不是空"+s5.isEmpty());
        System.out.println(s4.charAt(1));

        String s6 ="abccsf";
        String s7 = "abc";
        System.out.println(s6.equals(s7)); //true
        System.out.println(s6.compareTo(s7));

        String s8 ="skfsdjsihfais";
        System.out.println(s8.substring(3));
        System.out.println(s8.substring(3, 6));

        System.out.println(s8.concat("pppp"));
        System.out.println(s8.replace('s', 'u'));

        String s9 = "a-vs-dfa-s-s";
        String[] strs = s9.split("-");
        System.out.println(Arrays.toString(strs));

        //以后会经常用到
        String s10 = " a   b  c    ";
        System.out.println(s10.trim());

        System.out.println(String.valueOf(true));
    }
}
